package cn.xenosp.server.web.controller;

import cn.hutool.json.JSONObject;
import cn.xenosp.server.common.Result;
import cn.xenosp.server.common.annotation.LogInfo;
import cn.xenosp.server.common.sse.SseClient;
import cn.xenosp.server.common.sse.SseVO;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;

/**
 * 项目名： service-web
 * 包路径： cn.xenosp.server.web.controller
 * 作者：   TongHui
 * 创建时间: 2024-09-04 11:14
 * 描述: sse
 * 版本: 1.0
 */
@RestController
@RequestMapping("${app.config.api-base-url}/sse")
public class SseController {


    @LogInfo(operationModuleType = "SSE模块",operationName = "创建链接",operationContent = "创建链接")
    @PostMapping(value = "/connect")
    public SseEmitter streamSseMvc(@RequestBody SseVO sseVO) {
        return SseClient.createSse(sseVO);
    }


    @LogInfo(operationModuleType = "SSE模块",operationName = "获取会话",operationContent = "获取会话")
    @PostMapping(value = "/allSession")
    public Result<?> getSession() {
        try {
            return Result.OK("",SseClient.getAllSession());
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("服务错误",null);
        }
    }
}
